#include<bits/stdc++.h>

using namespace std;
using ll = long long;
#define endl '\n'
const int maxn = 1e6;
char a[maxn];
char b[30];

void tw(char a[]) {
    int ta = strlen(a);
    for (int i = 0; i < ta; i++) {
        a[i] = tolower(a[i]);
    }
}

void solve() {
    int t;
    cin >> t;
    while (t--) {
        cin >> b;
        int d = strlen(b);
        tw(b);
        char *pos = a;
        int tot = 0;
        while (pos = strstr(pos, b)) {
            if ((!isalpha(a[pos - a - 1])) && (!isalpha(a[pos - a + d]))) {
                tot++;
            }
            pos += d;
        }
        cout << tot << endl;
        memset(b, '0', sizeof(b));
    }
}

int main() {
//	freopen("E.txt","r",stdin);
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
//	fgets(a,60-1,stdin);
//	if(a[strlen(a)-1]=='\n') {
//		a[strlen(a)-1]=0;
//	}
    cin.getline(a, sizeof(a));
    tw(a);
    solve();
    return 0;
}